package uploads_api

import (
	"fmt"
	"gin_study_blog/common"
	"gin_study_blog/common/http"
	"gin_study_blog/models"
	"github.com/gin-gonic/gin"
)

// ImagesRemove 文件删除
func (UploadsApi) ImagesRemove(c *gin.Context) {
	var re models.RemoveRequest

	err := c.ShouldBindJSON(&re)
	if err != nil {
		http.FailWithCode(http.ParamsError, c)
		return
	}
	var imageList []*models.BannerModel
	// 查询文件是否存在数据库中
	count := common.DB.Debug().Find(&imageList, re.IdList).RowsAffected
	if count == 0 {
		http.FailWithMessage("文件不存在", c)
		return
	}
	// 在删除数据库数据
	common.DB.Delete(&imageList)
	http.IsOkWithMessage(fmt.Sprintf("共删除 %d 张图片", count), c)
}
